import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

import '../../../../common/cpn/sliver_app_bar.dart';

class HistoryPage extends StatelessWidget {
  // 模拟版本历史数据
  final List<VersionItem> _versions = [
    VersionItem(
      version: '8.0.35',
      date: DateTime(2025, 3, 15),
      features: ['新增动态消息封面效果', '群聊支持消息置顶', '优化语音消息播放体验', '修复已知问题'],
    ),
    VersionItem(
      version: '8.0.32',
      date: DateTime(2025, 1, 28),
      features: ['深色模式支持自定义色调', '聊天记录迁移到新设备', '朋友圈可编辑可见范围'],
    ),
    VersionItem(
      version: '8.0.28',
      date: DateTime(2024, 11, 5),
      features: ['新增状态表情包', '视频号直播支持连麦', '优化小程序打开速度'],
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[50],
      body: CustomScrollView(
        slivers: [
          commonSliverAppBar(
            title: '版本历史',
          ),
          SliverList(
            delegate: SliverChildBuilderDelegate(
              (context, index) => _buildVersionCard(_versions[index]),
              childCount: _versions.length,
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildVersionCard(VersionItem item) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
        boxShadow: [
          BoxShadow(
            color: Colors.black12,
            blurRadius: 6,
            offset: Offset(0, 2),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 版本标题区
          Padding(
            padding: EdgeInsets.all(16),
            child: Row(
              children: [
                Text(
                  'Version ${item.version}',
                  style: TextStyle(
                    fontSize: 18,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                Spacer(),
                Text(
                  DateFormat('yyyy.MM.dd').format(item.date),
                  style: TextStyle(color: Colors.grey),
                ),
              ],
            ),
          ),
          // 分割线
          Divider(height: 0, thickness: 0.5),
          // 更新内容列表
          Padding(
            padding: EdgeInsets.all(16),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '更新内容：',
                  style: TextStyle(color: Colors.grey[600]),
                ),
                SizedBox(height: 8),
                ...item.features.map((feature) => Padding(
                      padding: EdgeInsets.symmetric(vertical: 4),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(top: 4, right: 8),
                            child: Icon(
                              Icons.circle,
                              size: 6,
                              color: Colors.grey,
                            ),
                          ),
                          Expanded(
                            child: Text(
                              feature,
                              style: TextStyle(fontSize: 15),
                            ),
                          ),
                        ],
                      ),
                    )),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

class VersionItem {
  final String version;
  final DateTime date;
  final List<String> features;

  VersionItem({
    required this.version,
    required this.date,
    required this.features,
  });
}
